package xin.yangshuai.io01.hello;

import java.nio.ByteBuffer;

/**
 * Hello
 *
 * @author shuai
 * @date 2022/6/26
 */
public class Hello {

    public static void main(String[] args) {
        ByteBuffer buffer = ByteBuffer.allocate(1024);

        System.out.println(buffer.position());
        System.out.println(buffer.limit());
        System.out.println(buffer.capacity());

        System.out.println(buffer);

        buffer.put("123456".getBytes());
        buffer.put("123456".getBytes());

        System.out.println(buffer);

        //读取
        buffer.flip();

        System.out.println(buffer);

        //读取一个
        byte b = buffer.get();
        System.out.println((char)b);

        System.out.println(buffer);

        //写入
        buffer.compact();

        System.out.println(buffer);

        buffer.put("123456".getBytes());

        System.out.println(buffer);

        buffer.clear();

        System.out.println(buffer);
    }
}
